package academia.gui;

import academia.persistencia.PessoaDAO;
import academia.persistencia.TreinoDAO;
import academia.pessoal.Atendente;
import academia.pessoal.Pessoa;
import academia.pessoal.Treino;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class ListarTreinos extends javax.swing.JFrame {

    public ListarTreinos() {
        initComponents();
        listarTreinos();
    }

    public void listarTreinos() {
        Treino treino = new Treino();
        TreinoDAO treinodao = new TreinoDAO();

        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        try {
            tabelatreinos.setModel(treinodao.listar(treino.getIdCliente()));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Não há treinos cadastrados");
            throw new RuntimeException(e);

        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane2 = new java.awt.ScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelatreinos = new javax.swing.JTable();
        Voltar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tabelatreinos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabelatreinos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelatreinosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabelatreinos);

        scrollPane2.add(jScrollPane1);

        Voltar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        Voltar.setText("Voltar");
        Voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VoltarActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setText("Excluir Treino");

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setText("Editar Treino");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addGap(28, 28, 28)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addComponent(Voltar)
                .addGap(30, 30, 30))
            .addComponent(scrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(scrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton2)
                    .addComponent(Voltar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void VoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VoltarActionPerformed
       new TelaInstrutor().setVisible(true);
       this.dispose();
    }//GEN-LAST:event_VoltarActionPerformed

    private void tabelatreinosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelatreinosMouseClicked
        int linha = tabelatreinos.getSelectedRow();
        int click = (int) tabelatreinos.getModel().getValueAt(linha, 0);
        PessoaDAO.setId(click);
        jButton2.setEnabled(true);
        jButton3.setEnabled(true);

    }//GEN-LAST:event_tabelatreinosMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Voltar;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private java.awt.ScrollPane scrollPane2;
    private javax.swing.JTable tabelatreinos;
    // End of variables declaration//GEN-END:variables
}
